package entities;

//version 1.0

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

import smallTools.SimpleTime;

public class Section {

	private String id;
	private int size;
	private int duration;
	private SimpleTime startTime;
	private String roomId;
	private String staffId;

	// all the sections
	private static HashMap<String, Section> sectionHm = new HashMap<String, Section>();

	// constructor
	public Section(String id, int size, int duration, String staffId) {
		this.id = id;
		this.size = size;
		this.duration = duration;
		this.staffId = staffId;

		hashmap(id, this);
	}

	private void hashmap(String id, Section target) {
		if (sectionHm.get(id) == null)
			sectionHm.put(id, this);
	}

	public static Section getSectionById(String Id) {
		return sectionHm.get(Id);
	}

	public static String[] getSectionIdList() {
		Iterator<String> sectionId = sectionHm.keySet().iterator();
		String[] sectionIdList = new String[sectionHm.size()];
		int i = 0;
		while (sectionId.hasNext()) {
			sectionIdList[i++] = sectionId.next();
		}
		Arrays.sort(sectionIdList);

		return sectionIdList;
	}

	public static int getTotalSectionSize() {
		return sectionHm.size();
	}

	public int getSectionDuration() {
		return this.duration;
	}

	public int getSectionSize() {
		return this.size;
	}

	public String getSectionId() {
		return this.id;
	}

	public SimpleTime getSectionStartTime() {
		return this.startTime;
	}

	public void setSectionStartTime(SimpleTime startTime) {
		this.startTime = startTime;
	}

	public String getSectionRoomId() {
		return this.roomId;
	}

	public String getSectionStaffId() {
		return this.staffId;
	}

	public void setSectionRoom(String roomId) {
		this.roomId = roomId;
	}

	public String toString() {
		String output;
		if (this.startTime == null) {
			output = this.id + " " + Integer.toString(this.size)
					+ " Unspecified Time Slot and Room " + this.staffId;
			return output;
		} else {
			output = this.id + " " + Integer.toString(this.size) + " "
					+ this.startTime.toString() + " "
					+ this.startTime.getEndTime(this.duration).toString() + " "
					+ this.roomId + " " + this.staffId;
			return output;
		}
	}

	public static void clear() {
		sectionHm.clear();
	}
}
